package com.qqtech.qquan.pub.service;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.service.BaseServiceImpl;
import com.qqtech.qquan.pub.dao.PubPromotionDao;
import com.qqtech.qquan.pub.model.*;

@Service
public class PubPromotionServiceImpl extends BaseServiceImpl<PubPromotion> implements PubPromotionService {
	public static final Logger log = LoggerFactory.getLogger(PubPromotionServiceImpl.class);

	@Resource
	private PubPromotionDao pubPromotionDao;

	@Override
	protected BaseDao<PubPromotion> getBaseDao() {
		return pubPromotionDao;
	}

	@Override
	public boolean isTargetPromotion(Integer targetBizzId, Integer targetBizzType) {
		boolean isPromotion = false;
		PubPromotionQuery pubPromotionQuery = new PubPromotionQuery();
		pubPromotionQuery.setTargetBizzId(targetBizzId);
		pubPromotionQuery.setTargetBizzType(targetBizzType);
		int count = pubPromotionDao.queryCount(pubPromotionQuery);
		if (count > 0) {
			isPromotion = true;
		}
		return isPromotion;
	}

	@Override
	public boolean isSourcePromotion(Integer sourceBizzId, Integer sourceBizzType) {
		boolean isPromotion = false;
		PubPromotionQuery pubPromotionQuery = new PubPromotionQuery();
		pubPromotionQuery.setSourceBizzId(sourceBizzId);
		pubPromotionQuery.setSourceBizzType(sourceBizzType);
		int count = pubPromotionDao.queryCount(pubPromotionQuery);
		if (count > 0) {
			isPromotion = true;
		}
		return isPromotion;
	}

	@Override
	public List<PubPromotionVo> getPubPromotionVoByTarget(Integer targetBizzId, Integer targetBizzType) {
		PubPromotionQuery pubPromotionQuery = new PubPromotionQuery();
		pubPromotionQuery.setTargetBizzId(targetBizzId);
		pubPromotionQuery.setTargetBizzType(targetBizzType);
		List<PubPromotionVo> list = pubPromotionDao.queryList(pubPromotionQuery);
		return list;
	}

	@Override
	public List<PubPromotionVo> getPubPromotionVoBySource(Integer sourceBizzId, Integer sourceBizzType) {
		PubPromotionQuery pubPromotionQuery = new PubPromotionQuery();
		pubPromotionQuery.setSourceBizzId(sourceBizzId);
		pubPromotionQuery.setSourceBizzType(sourceBizzType);
		List<PubPromotionVo> list = pubPromotionDao.queryList(pubPromotionQuery);
		return list;
	}

	@Override
	public PubPromotionVo getPubPromotionVo(Integer targetBizzId, Integer targetBizzType, Integer sourceBizzId,
			Integer sourceBizzType) {
		PubPromotionVo pubPromotionVo=null;
		PubPromotionQuery pubPromotionQuery = new PubPromotionQuery();
		pubPromotionQuery.setSourceBizzId(sourceBizzId);
		pubPromotionQuery.setSourceBizzType(sourceBizzType);
		pubPromotionQuery.setTargetBizzId(targetBizzId);
		pubPromotionQuery.setTargetBizzType(targetBizzType);
		List<PubPromotionVo> list = pubPromotionDao.queryList(pubPromotionQuery);
		if(null!=list&&list.size()>0){
			pubPromotionVo=list.get(0);
		}
		return pubPromotionVo;
	}

}